﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Configuration;
using System.IO;
using System.Net;

/// <summary>
/// Summary description for SendMail
/// </summary>
public class SendMail
{
    public SendMail()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public int SendRegisterMail(string ToMail, string Name, string Login, string Password)
    {
        try
        {
            MailMessage message = new MailMessage();
            string FromMails = string.Empty;
            string FromUser = string.Empty;

            FromMails = "nanthinielangovan@gmail.com";
            String to = "nanthinielangovan@gmail.com";

            message.From = new MailAddress(FromMails);
            message.To.Add(new MailAddress(to));



            StreamReader srGetMailBody;
            string strMailBody;


            srGetMailBody = File.OpenText(HttpContext.Current.Server.MapPath("~") + "/MailTemplate/MailTemplate.txt");


            strMailBody = srGetMailBody.ReadToEnd().ToString();
            strMailBody = strMailBody.Replace("<<#Banner1#>>", "http://do4u.in/img/logo.png");

            message.Subject = "Reg:Forget Password From Gems";
            strMailBody = strMailBody.Replace("<<#FinalMsg#>>", "Kindly Change Your Password Once You Login.,<a href='#'>Click here</a> to login");
            strMailBody = strMailBody.Replace("<<#Name#>>", Name);
            strMailBody = strMailBody.Replace("<<#LoginId#>>", Login);
            strMailBody = strMailBody.Replace("<<#Password#>>", Password);

            message.Body = strMailBody;

            if (string.IsNullOrEmpty(strMailBody))
            {
                message.IsBodyHtml = false;
            }
            else
            {
                message.IsBodyHtml = true;
            }
            //Sends the mail 



            //Sends the mail          
            SmtpClient SmtpMail = new SmtpClient("smtp.gmail.com", 587);
            SmtpMail.UseDefaultCredentials = false;
            SmtpMail.Host = "smtp.gmail.com";
            SmtpMail.EnableSsl = true;
            SmtpMail.Credentials = new NetworkCredential("nanthinielangovan@gmail.com", "nanthu1989");
            SmtpMail.Send(message);
            return 0;
        }
        catch (Exception ex)
        {
            string s = ex.Message;
            return 1;
        }
    }
}
